home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 December / PCWorld_2007-12_cd.bin / domacnost a kancelar / autoit / autoit-v3-setup.exe / Examples / Helpfile / _SQLite_GetTable.au3 < prev    next >
Text File  |  2007-09-08  |  2KB  |  53 lines

  1. #include <SQLite.au3>
  2. #include <SQLite.dll.au3>
  3. #include <Array.au3>
  4.  
  5. Local $aResult, $iRows, $iColumns, $iRval
  6.  
  7. _SQLite_Startup ()
  8. If @error > 0 Then
  9.     MsgBox(16, "SQLite Error", "SQLite.dll Can't be Loaded!")
  10.     Exit - 1
  11. EndIf
  12. _SQLite_Open () ; Open a :memory: database
  13. If @error > 0 Then
  14.     MsgBox(16, "SQLite Error", "Can't Load Database!")
  15.     Exit - 1
  16. EndIf
  17.  
  18. ;Example Table
  19. ;     Name        | Age
  20. ;     -----------------------
  21. ;     Alice       | 43
  22. ;     Bob         | 28
  23. ;     Cindy       | 21
  24.  
  25. If Not _SQLite_Exec (-1, "CREATE TEMP TABLE persons (Name, Age);") = $SQLITE_OK Then _
  26.         MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
  27. If Not _SQLite_Exec (-1, "INSERT INTO persons VALUES ('Alice','43');") = $SQLITE_OK Then _
  28.         MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
  29. If Not _SQLite_Exec (-1, "INSERT INTO persons VALUES ('Bob','28');") = $SQLITE_OK Then _
  30.         MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
  31. If Not _SQLite_Exec (-1, "INSERT INTO persons VALUES ('Cindy','21');") = $SQLITE_OK Then _
  32.         MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
  33.  
  34. ; Query
  35. $iRval = _SQLite_GetTable (-1, "SELECT * FROM persons;", $aResult, $iRows, $iColumns)
  36. If $iRval = $SQLITE_OK Then
  37. ;~     $aResult Looks Like this:
  38. ;~         [0]    = 8
  39. ;~         [1]    = Name
  40. ;~         [2]    = Age
  41. ;~         [3]    = Alice
  42. ;~         [4]    = 43
  43. ;~         [5]    = Bob
  44. ;~         [6]    = 28
  45. ;~         [7]    = Cindy
  46. ;~         [8]    = 21
  47.     _ArrayDisplay($aResult, "Query Result")
  48. Else
  49.     MsgBox(16, "SQLite Error: " & $iRval, _SQLite_ErrMsg ())
  50. EndIf
  51.  
  52. _SQLite_Close ()
  53. _SQLite_Shutdown ()